package com.fpc.cn.springbootutil.mybatisLog;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @date 2025/4/27
 * @author fupengcheng
 * @describe
 */
public class SqlStorage {
    private static ThreadLocal<List<SqlVO>> sqlList = new ThreadLocal();

    public SqlStorage() {
    }

    public static void setSql(SqlVO sqlVo) {
        List<SqlVO> sqls = (List)sqlList.get();
        if (Objects.isNull(sqls)) {
            sqls = new ArrayList(20);
            sqlList.set(sqls);
        }

        ((List)sqls).add(sqlVo);
    }

    public static List<SqlVO> getSql() {
        return (List)Optional.ofNullable(sqlList.get()).orElse(Collections.EMPTY_LIST);
    }

    public static void remove() {
        sqlList.remove();
    }
}